package service

import (
	"zzxq/models"
	"zzxq/repository/tagrepository"
)

type TagService struct {

}

//获取全部标签
func (tag *TagService) GetUserAllTage(uid int) []models.SysTag {
	sysTag := tag.GetSysTag()

	if uid > 0 {
		userTage := tag.GetUserTags(uid)
		sysTag = append(sysTag, userTage...)
	}

	return sysTag
}

//获取系统标签
func (tag *TagService) GetSysTag() []models.SysTag {
	return models.GetSysTag()
}

//获取用户自定义标签
func (tag *TagService) GetUserTags(uid int) []models.SysTag {
	dbrep := &tagrepository.DbUserTag{}

	userTage := dbrep.GetUserTagList(uid)

	var tags []models.SysTag = make([]models.SysTag, len(userTage))
	for key, value := range userTage {
		tags[key].Id = value.Id
		tags[key].Title = value.Title
	}

	return tags
}

//创建用户自定义标签
func (tag *TagService) CreateUserTag(uid int, title string) bool {
	dbrep := &tagrepository.DbUserTag{}

	return dbrep.CreateUserTag(uid, title)
}